using Game.Core;
using Game.Main.Model;
using Game.Main.View;
using Game.Manager;
using Game.XH;
using UnityEngine;

namespace Game.Component
{
	public class CurtainRopeItem : BaseItem
	{
		public enum Anim
		{
			Static = 0,
			Down = 1,
			Up = 2
		}

		private float UP_POSITION;

		private float DOWN_POSITION = -0.3f;

		private Anim anim;

		private float animTimer;

		private Transform rope;

		private Transform curtain;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			rope = model.Find("Rope");
			curtain = model.Find("Curtain");
			curtain.SetLocalZ(1E-05f);
		}

		protected override void LateUpdate()
		{
			if (anim == Anim.Static)
			{
				return;
			}
			animTimer += Time.deltaTime;
			if (anim == Anim.Down)
			{
				rope.SetLocalY(Mathf.Lerp(UP_POSITION, DOWN_POSITION, animTimer * 5f));
				if (animTimer >= 0.2f)
				{
					anim = Anim.Up;
					animTimer = 0f;
					BaseItem itemByScriptType = Singleton<Scene>.Instance.GetItemByScriptType(47);
					if (itemByScriptType != null)
					{
						((CurtainItem)itemByScriptType).ChangeNextCurtain();
					}
				}
			}
			else if (anim == Anim.Up)
			{
				rope.SetLocalY(Mathf.Lerp(DOWN_POSITION, UP_POSITION, animTimer * 2f));
				if (animTimer >= 0.5f)
				{
					anim = Anim.Static;
				}
			}
		}

		public override void QuicklyTouch(TouchEventData touchEventData)
		{
			base.QuicklyTouch(touchEventData);
			if (anim == Anim.Static)
			{
				BaseItem itemByScriptType = Singleton<Scene>.Instance.GetItemByScriptType(47);
				if (itemByScriptType != null && ((CurtainItem)itemByScriptType).CanChangeCurtain())
				{
					anim = Anim.Down;
					animTimer = 0f;
					Singleton<AudioManager>.Instance.PlaySound("sound_curtain");
				}
			}
		}
	}
}
